package org.finalministry.gui.panels;

import javax.swing.JPanel;
import javax.swing.SpringLayout;

import org.finalministry.gui.components.CountrySelector;
import org.finalministry.gui.components.FLabel;
import org.finalministry.gui.utils.SpringUtilities;
import org.finalministry.objects.address.Address;

public class NewAddressPanel extends JPanel {

	private static final long serialVersionUID = -6802115718182346809L;

	private FTextField street;
	private FTextField housenumber;
	private FTextField postalcode;
	private FTextField city;
	private CountrySelector countrySelector;

	public NewAddressPanel() {
		this.setLayout(new SpringLayout());

		FLabel labelStreet = new FLabel("Street: ");
		this.add(labelStreet);
		street = new FTextField();
		this.add(street);

		FLabel labelHousenumber = new FLabel("Housenumber: ");
		this.add(labelHousenumber);
		housenumber = new FTextField();
		this.add(housenumber);

		FLabel labelPostalcode = new FLabel("Postalcode: ");
		this.add(labelPostalcode);
		postalcode = new FTextField();
		this.add(postalcode);

		FLabel labelCity = new FLabel("City: ");
		this.add(labelCity);
		city = new FTextField();
		this.add(city);

		FLabel labelCountry = new FLabel("Country: ");
		this.add(labelCountry);
		countrySelector = new CountrySelector();
		this.add(countrySelector);

		SpringUtilities.makeCompactGrid(this, // parent
				5, 2, 3, 3, // initX, initY
				3, 3); // xPad, yPad
	}

	public Address getAddress() {

		Address address = new Address();
		address.setStreet(street.getText());
		address.setHousenumber(housenumber.getText());
		address.setPostalcode(postalcode.getText());
		address.setCity(city.getText());
		address.setCountry(countrySelector.getSelectedCountry());

		return address;
	}

}
